//
//  SNGiftModel.m
//  app
//
//  Created by 王少宁 on 15/6/19.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNGiftModel.h"
#import "NSDictionary+SafetyGet.h"

@implementation SNGiftModel

- (instancetype)initWithDict:(NSDictionary *)dict
{
    if ([super init]) {
        
        NSArray * giftArray = dict[@"list"];
        NSDictionary * giftDic = @{};
        
        for(NSDictionary *item in giftArray) {
            if ([item boolForKey:APIKEY_mall_selected]) {
                giftDic = item;
                break;
            }
        }
        if ([giftDic[@"product_id"] intValue]) {
            _gift = YES;
        } else {
            _gift = NO;
        }
        
        _title = giftDic[@"title"];
        _product_id = [giftDic stringForKey:@"product_id" nilValue:@""];//dict[@"product_id"];
        _pic = giftDic[@"pic"];
        _width = [giftDic[@"width"] stringValue];
        _height = [giftDic[@"width"] stringValue];
    }
    return self;
}

+ (instancetype)modelWithDict:(NSDictionary *)dict
{
    return [[self alloc] initWithDict:dict];
}

@end
